package com.dsteiner.gwt.cafeteriasophia.client;

import java.beans.PropertyChangeListener;

import com.dsteiner.gwt.cafeteriasophia.client.controller.ChangesController;
import com.dsteiner.widgets.client.PopupOverlayWidget;
import com.dsteiner.widgets.client.PrefilledTextBox;
import com.dsteiner.widgets.client.PropertyChangeCollection;
import com.dsteiner.widgets.client.Widgets.ButtonExt;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.HTMLExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.event.EventManagerImpl;
import com.dsteiner.widgets.client.model.PopupOverlayModel;
import com.dsteiner.widgets.client.model.PrefilledTextBoxModel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ChangesWidget extends LazyWidget {

	public static class ChangesModel {
		private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(
				this);

		public void addPropertyChangeListener(String propertyName,
				PropertyChangeListener listener) {
			propertyChangeSupport.registerPropertyChangeListener(propertyName,
					listener);
		}
		
	}

	private ChangesController changesController = new ChangesController();
	private final ChangesModel changesModel;
	private FlowPanelExt contentPanel = new FlowPanelExt();
	PopupOverlayModel popupOverlayModel = new PopupOverlayModel();
	PopupOverlayWidget popupOverlayWidget = new PopupOverlayWidget(popupOverlayModel);
	HTMLExt titleHtml = new HTMLExt();
	
	public ChangesWidget(ChangesModel changesModel) {
		this.changesModel = changesModel;
		changesController.registerChangesWidget(this);
		changesController.registerContentPanel(contentPanel);
		changesController.registerChangesModel(changesModel);
		changesController.registerPopupOverlayModel(popupOverlayModel);
		changesController.registerEventManager(EventManagerImpl.getInstance());
		changesController.registerTitleHtml(titleHtml);
		popupOverlayModel.setContentWidget(this);
		
		setStyleName("changes-widget");
	}

	@Override
	public Widget createContentWidget() {
		FlowPanel mainPanel = new FlowPanel();
		ButtonExt checkShiftButton = new ButtonExt("chequear cambio de turno ahora");
		ButtonExt addShiftButton = new ButtonExt("ingresar cambio de turno ahora");
		PrefilledTextBoxModel codeTextBoxModel = new PrefilledTextBoxModel();
		codeTextBoxModel.setDefaultText("ingrese el codigo para ingresar el turno");
		PrefilledTextBox codeTextBox = new PrefilledTextBox(codeTextBoxModel);
		
		HorizontalPanel actionPanel = new HorizontalPanel();
		actionPanel.setSpacing(5);
		actionPanel.add(codeTextBox);
		actionPanel.add(addShiftButton);
		
		mainPanel.add(titleHtml);
		mainPanel.add(contentPanel);
		mainPanel.add(actionPanel);
		
		changesController.registerCheckShiftButton(checkShiftButton);
		changesController.registerAddShiftButton(addShiftButton);
		changesController.registerCodeTextBoxModel(codeTextBoxModel);
		return mainPanel;
	}

}